#include "stdafx.h"
#include "CG6-HeartRate.h"


HANDLE g_hHeart = INVALID_HANDLE_VALUE;

int GetHeartRate()
{
	if ( g_hHeart ==INVALID_HANDLE_VALUE )
	{
		 g_hHeart = CreateFile(TEXT("HRT1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
	}

	DWORD dwGet=0,dummy=0;
	if ( g_hHeart != INVALID_HANDLE_VALUE)	
	{
		ReadFile( g_hHeart, &dwGet, sizeof(dwGet), &dummy, NULL );
	}
	else	
	{
		//printf( "can't open device HRT1:\r\n");
	}

	return dwGet;
}

void CloseHearteRateRead()
{
	if ( g_hHeart !=INVALID_HANDLE_VALUE )
		CloseHandle( g_hHeart );
	g_hHeart = INVALID_HANDLE_VALUE;
}